﻿#region license
# This file is part of Grawlix.
# 
# Grawlix is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
# 
# Grawlix is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public
# License along with Grawlix.  If not, see
# <http://www.gnu.org/licenses/>.
#endregion

"""Find return statements in a method."""

namespace Grawlix.Meta
import System
import Boo.Lang.Compiler

class ReturnExpressionFinder(Ast.DepthFirstVisitor):
"""
Find any return or yield statements within a method.
Remarks: Copied from
	Boo.Lang.Compiler.Steps.ProcessMethodBodies.ReturnExpressionFinder
	and converted to boo from C#.
"""
	
	def Apply(node as Ast.Method):
	"""
	Look for return statements.
	Param node: The method to search.
	"""
		Visit(node.Body)
	
	[getter(HasReturnStatements)]
	private _hasReturnStatements as bool
	"""Whether any value return statements were found."""
	
	[getter(HasYieldStatements)]
	private _hasYieldStatements as bool
	"""Whether any yield statements were found."""
	
	override def OnReturnStatement(node as Ast.ReturnStatement):
	"""
	Act upon a return statement.
	Param node: The return statement.
	"""
		_hasReturnStatements |= (null != node.Expression)
		
	override def OnYieldStatement(node as Ast.YieldStatement):
	"""
	Act upon a yield statement.
	Param node: The yield statement.
	"""
		_hasYieldStatements = true
